package com.dkd.day20250619;

import com.dkd.day20250616.TreeNode;

import java.util.LinkedList;
import java.util.Queue;

public class SolutionisCompleteTree {
    public static void main(String[] args) {

    }

     public boolean isCompleteTree (TreeNode root) {
        // write code here
        //非空判断
        if(root == null) return true;
        //辅助队列
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        //定义首次出现的标记位
        boolean hasNull = false;
        while(!queue.isEmpty()){
            TreeNode cur = queue.poll();
            if(cur == null){
                hasNull=true;
            }else{
                if(hasNull){
                    return false;
                }
                queue.offer(cur.left);
                queue.offer(cur.right);
            }
        }
        return true;
    }
}
